﻿using UnityEngine;
using System.Collections;
using System.Reflection;
using System;

namespace iTManager
{
    public class iTweenProperty
    {
        public static Hashtable GetProperties(IiTweenProperty pro)
        {
            Hashtable hastable = new Hashtable();
            foreach (var p in pro.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                string name = p.Name;
                object value = p.GetValue(pro, null);
                Type type = p.PropertyType;
                if (name.Contains("_")) name = name.Split('_')[0];
                if ((
                        type.Equals(typeof(iTweenBase.EaseType)) && (iTweenBase.EaseType)value != iTweenBase.EaseType.none
                        ||
                        type.Equals(typeof(iTweenBase.LoopType)) && (iTweenBase.LoopType)value != iTweenBase.LoopType.none
                        ||
                        type.Equals(typeof(iTweenBase.NamedValueColor)) && (iTweenBase.NamedValueColor)value != iTweenBase.NamedValueColor._None
                        ||
                        type.Equals(typeof(Space)) && (Space)value == Space.World
                        ||
                        type.Equals(typeof(string)) && value != null && (string)value != string.Empty
                        ||
                        type.Equals(typeof(bool)) && ((bool)value || ((name == "includechildren" || name == "movetopath") && !(bool)value))
                        ||
                        ((type.Equals(typeof(float?)) || type.Equals(typeof(Color?)) || type.Equals(typeof(Rect?)) || type.Equals(typeof(Vector2?)) || type.Equals(typeof(Vector3?)) || type.Equals(typeof(Vector3[])) || type.Equals(typeof(Transform[]))) && value != null)
                    ))
                {
                    hastable.Add(name, value);
                }
            }
            return hastable;
        }
    }
}
